<?php

namespace App\Http\Controllers\Common;

use App\Tools\Files;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Intervention\Image\ImageManager;

class WebUploaderCtrl extends Controller
{
    //
    public function index()
    {
        $files = \request()->files;
        foreach ($files as $file) {
            $obj = new Files($file);
            $success = $obj->imgUploader();
            return $success === false ? $this->error('上传失败') : $this->success('上传成功', '', $success);
        }
    }

    /*转移文件*/
    public function move()
    {
        $val = \request()->get('val');
        $val = substr($val, 1);
        $moveUrl = \request()->get('moveUrl');
        $moveUrl = substr($moveUrl, 1);
        #dd(public_path($val));

        $manager = new ImageManager();
        $info = $manager->make($val);

        $newPath = $moveUrl . uniqid() . '.' . $info->extension;
        $query = Storage::copy($val, $newPath);
        $query ? $this->success('', '', '/' . $newPath) : $this->error('flash');
    }
}
